<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>日期取值</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>

</head>
<body>
<script>

    $(document).ready(function () {

        var today = new Date();
        alert(setDate(today));

        var date = new Date();

        //本月第一天
        var startDay = new Date(new Date().getFullYear(), new Date().getMonth(), 1);
        alert(setDate(startDay));
        //本月最后一天
        var day = new Date(date.getFullYear(), date.getMonth(), 0).getDate();
        var endDay = new Date(new Date().getFullYear(), new Date().getMonth(), day);
        alert(setDate(endDay));

        // 获取上个月第一天
        var firstdate = new Date(new Date().getFullYear(), new Date().getMonth()-1, 1);
        alert(setDate(firstdate));
        //获取上个月最后一天
        day = new Date(date.getFullYear(), date.getMonth(), 0).getDate();
        var enddate = new Date(new Date().getFullYear(), new Date().getMonth()-1, day);
        alert(setDate(enddate));

        //格式化日期
        function setDate(date) {
            y = date.getFullYear();
            m = date.getMonth() + 1;
            d = date.getDate();
            m = m < 10 ? "0" + m : m;
            d = d < 10 ? "0" + d : d;
            return y + "-" + m + "-" + d;
        }

    });
</script>
</body>
</html>